import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/project_same_time_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/same_time_entity.dart';
import 'package:get/get.dart';

class ThreeSameTimeDetailsController extends GetxController {
  /// 文件id
  final String id = Get.arguments as String;

  /// 详情数据
  SameTimeEntity entity = SameTimeEntity();

  /// 详情列表
  List<ProjectSameTimeEntity> dataList = [];

  @override
  void onInit() {
    super.onInit();
    getDetailsData();
  }

  /// 获取详情数据
  void getDetailsData() async {
    // 获取详情接口
    final res = await HttpUtil().generateGetRequest<SameTimeEntity>(
      Interface.getProjectSameTime,
      queryParameters: {'id': id},
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        entity = result.data!;
        // 设计阶段
        if (entity.design.id!.isNotEmpty) {
          entity.design.statusName = '设计';
          entity.nowStatus = '设计';
          dataList.add(entity.design);
        }
        // 施工阶段
        if (entity.construction.id!.isNotEmpty) {
          entity.construction.statusName = '施工';
          entity.nowStatus = '施工';
          dataList.add(entity.construction);
        }
        // 试运行阶段-
        if (entity.trialProduction.id!.isNotEmpty) {
          entity.trialProduction.statusName = '试运行';
          entity.nowStatus = '试运行';
          dataList.add(entity.trialProduction);
        }
        // 取消阶段
        if (entity.cancel.id!.isNotEmpty) {
          entity.cancel.statusName = '取消';
          entity.nowStatus = '取消';
          dataList.add(entity.cancel);
        }
      }
      update();
    });
  }
}
